//
//  HeadView.m
//  HappyStore
//
//  Created by 李小辉 on 16/6/30.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "HeadView.h"

@implementation HeadView

-(void)setInit:(Person *)person{

    if (person.userName == nil || [person.userName isEqualToString:@"null"]) {
        
        self.nameStr.text = person.account;
        
    }else {
        
        self.nameStr.text = person.userName;
        
        ;
        
    }
    
    if ([person.usertype integerValue] == 1) {//个人
        
        
        //positionName-
        //goveAccount 政府账户
        //companyAccount 企业帐户
        
        if (person.positionName == nil || [person.positionName isEqualToString:@"null"]) {
            self.positionNameStr.text = @"";
        }else {
            self.positionNameStr.text = person.positionName;
            
        }
        
        if ([person.companyName isEqualToString:@"null"] || [person.companyName isEqualToString:@""] || person.companyName == nil) {
            if ([person.address isEqualToString:@"null"] || person.address == nil) {
                self.companyUserNameStr.text = @" ";
            }else{
                self.companyUserNameStr.text = person.address;
            }
        }else{
            self.companyUserNameStr.text = person.companyName;
        }
        
        
    }else if ([person.usertype integerValue] == 2) {//企业
        
        //没有职位
        self.positionNameStr.text = @"";
        
        if ([person.address isEqualToString:@"null"] || person.address == nil) {
            self.companyUserNameStr.text = @" ";
        }else{
            self.companyUserNameStr.text = person.address;
        }
        
    }else {//政府
        self.positionNameStr.text = @"";
        if ([person.address isEqualToString:@"null"] || person.address == nil) {
            self.companyUserNameStr.text = @" ";
        }else{
            self.companyUserNameStr.text = person.address;
        }
        
        
    }
    
    //认证
    self.isAuthState.hidden = [UsedTool authStateImageViewHidden:person.authState];
    //会员图标
    self.vStr.image = [UsedTool setVipimage:person.vipLevel];
    //头像
    NSData * data = person.headPhoto;
    UIImage * image = [UIImage imageWithData: data];
    self.imgStr.image = image;
    
    if ([person.mobile isEqualToString:@"null"] || [person.mobile isEqualToString:@""] || person.mobile == nil) {
        
        self.phoneStr.text = @"暂未添加";
    }else{
        self.phoneStr.text = person.mobile;
    }
    
    if ([person.email isEqualToString:@""] || [person.email isEqualToString:@"null"]) {
        
        self.emailStr.text = @"暂未添加邮箱";
        
    }else{
        self.emailStr.text = person.email;
    }
    CGSize nameSize = [self.nameStr sizeThatFits:CGSizeMake(MAXFLOAT, 20)];
    if (self.nameConstraint.constant == 220) {
        if (nameSize.width > 150) {
            self.nameConstraint.constant -= 160;
        }else{
            self.nameConstraint.constant -= nameSize.width;
        }
    }
    
    CGSize nameSizeCon = [self.nameStr sizeThatFits:CGSizeMake(160, MAXFLOAT)];
    CGSize addressSize = [self.companyUserNameStr sizeThatFits:CGSizeMake(screenW - 150, MAXFLOAT)];
    
    if (addressSize.height >= 30) {
        self.frame = CGRectMake(0, 0, screenW, self.height - self.nameStr.height + nameSizeCon.height + addressSize.height - 30);
    }else{
        self.frame = CGRectMake(0, 0, screenW, self.height - self.nameStr.height + nameSizeCon.height);
    }

//    return self.height;
}

@end
